#!/usr/bin/env python
# -- coding=utf-8 --
from tornado import httpserver, ioloop, options
from tornado.web import *

options.define("port", 8000, type=int, help="请输入端口号")


class IndexHandler(RequestHandler):
    def post(self):
        img_files = self.request.files.get("img")
        print(img_files[0])
        filname = img_files[0].get("filename", "test.png")
        img_file = img_files[0].get("body")
        with open("./" + filname, "wb") as fw:
            fw.write(img_file)

        self.write("hello")


def main():
    options.options.parse_command_line()
    print(options.options.port)
    app = Application([
        (r'/', IndexHandler),
    ])
    http_server = httpserver.HTTPServer(app)
    http_server.listen(options.options.port)
    ioloop.IOLoop.current().start()


if __name__ == '__main__':
    main()
